package com.boang.lock;

/*
    @author:sa
    @date:2024/11/26 13:58
*/
public class TicketDemoSysMethod04 implements Runnable {
    private int num = 20;

    @Override
    public void run() {
        while (true) {
            sale();
        }
    }
    private synchronized void sale() {
        if (num > 0) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println(Thread.currentThread().getName() + ":" + num--);
        }
    }
}